package com.example.Sao.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.Sao.MyActivity.ChangeDeviceActivity;
import com.example.Sao.ObjectBox.DeviceEntity;
import com.example.Sao.R;
import com.google.gson.Gson;

import java.util.List;

import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;

/**
 * @ProjectName: scan
 * @Package: com.example.MyApplication.Adapter
 * @ClassName: ChecklistAdpter
 * @Description: 设备信息适配器
 * @Author: 阿毛
 * @CreateDate: 2020/4/21 22:36
 * @UpdateUser: 更新者：
 * @UpdateDate: 2020/4/21 22:36
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class DeviceInfoAdpter extends RecyclerView.Adapter<DeviceInfoAdpter.mViewHolder>{
    private Context context;
    private List<DeviceEntity> InfoBeanList;

    public void setInfoBeanList(List<DeviceEntity> infoBeanList) {
        InfoBeanList = infoBeanList;
    }

    public DeviceInfoAdpter(Context context, List<DeviceEntity>InfoBeanList){
        this.context = context;
        this.InfoBeanList = InfoBeanList;
    }

    @NonNull
    @Override
    public mViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(context).inflate(R.layout.adpter_list_check_layout,viewGroup,false);
        return new mViewHolder(view);
    }

    @Override
    public int getItemCount() {
        return InfoBeanList.size();
    }

    @Override
    public void onBindViewHolder(@NonNull mViewHolder mViewHolder, int i) {
        DeviceEntity deviceEntity = InfoBeanList.get(i);
        if (deviceEntity.isStaus()) {
            mViewHolder.iv_status.setText("已盘点");
        }else {
            mViewHolder.iv_status.setText("未盘点");
        }
        mViewHolder.iv_code.setText("流水号:"+deviceEntity.getDeviceStreamCode());
        mViewHolder.iv_name.setText("设备名称:"+deviceEntity.getDeviceName());
        mViewHolder.iv_floor.setText("所在楼层:"+deviceEntity.getLocationFloor());
        mViewHolder.iv_era.setText("所在区域:"+deviceEntity.getLocationPosition());
        mViewHolder.iv_room.setText("所在房间号:"+deviceEntity.getLocationRoom());
        mViewHolder.iv_box.setText("所在货架号:"+deviceEntity.getLocationIbm());
        mViewHolder.partmnet.setText(deviceEntity.getUseDepartment());
               mViewHolder.iv_code.setOnClickListener(new View.OnClickListener() {
                   @Override
                   public void onClick(View v) {
                      Intent intent =  new Intent(context, ChangeDeviceActivity.class);
                      intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
                      intent.putExtra("devicemess",new Gson().toJson(deviceEntity));
                       context.startActivity(intent);
                   }
               });
    }

    class mViewHolder extends RecyclerView.ViewHolder{
        private AppCompatTextView iv_code,iv_era,iv_floor,iv_room,iv_box,iv_name,iv_status,partmnet;
        public mViewHolder(View v){
            super(v);
            partmnet = v.findViewById(R.id.partmnet);
            iv_code = v.findViewById(R.id.code);
            iv_era = v.findViewById(R.id.iv_era);
            iv_floor = v.findViewById(R.id.iv_floor);
            iv_room = v.findViewById(R.id.iv_room);
            iv_box = v.findViewById(R.id.iv_box);
            iv_name = v.findViewById(R.id.iv_name);
            iv_status = v.findViewById(R.id.check_status);
        }
    }
}
